<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>2-路由重定向</title>
    <!-- 导入 vue 文件 -->
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
  </head>
  <body>
    <div id="app">
      <router-link to="/user1">User1</router-link>
      <router-link to="/user2">User2</router-link>
      <router-view></router-view>
    </div>
    <script>
      var User1 = {
        template: `<h1>User1 - 组件</h1>`,
      };
      var User2 = {
        template: `<h1>User2 - 组件</h1>`,
      };
      // redirect路由重定向
      const router = new VueRouter({
        routes: [
          {
            path: '/',
            redirect: '/user1',
          },
          {
            path: '/user1',
            component: User1,
          },
          {
            path: '/user2',
            component: User2,
          },
        ],
      });

      const vm = new Vue({
        el: '#app',
        data: {},
        router,
      });
    </script>
  </body>
</html>
